package com.nj9you.sdk.utils;

import android.text.TextUtils;

import com.nj9you.sdk.constant.Constants;


/**
 * 参数检查
 *
 * @author zuixin_zhou
 */
public class ParamsValidator {

    /**
     * 检查用户名是否符合规则
     *
     * @param username
     * @throws IllegalArgumentException
     */
    public static void checkUsername(String username)
            throws IllegalArgumentException {

        if (TextUtils.isEmpty(username)) {
            throw new IllegalArgumentException(Constants.USERNAME_IS_EMPTY);
        } else if (!Utils.doRegularExpression(Constants.USERNAME_REGRXP, username)) {
            throw new IllegalArgumentException(Constants.USERNAME_FORMERR);
        }

    }

    /**
     * 检查密码是否符合规则
     *
     * @param password
     * @throws IllegalArgumentException
     */
    public static void checkPwd(String password) {

        if (TextUtils.isEmpty(password)) {
            throw new IllegalArgumentException(Constants.PWD_IS_EMPTY);
        } else if (!Utils.doRegularExpression(Constants.PWD_REGRXP, password)) {
            throw new IllegalArgumentException(Constants.PWD_FORMERR);
        }
    }

    /**
     * 检查电话号码是否符合规则
     *
     * @param telphone
     * @throws IllegalArgumentException
     */
    public static void checkTelphone(String telphone) {

        if (TextUtils.isEmpty(telphone)) {
            throw new IllegalArgumentException(Constants.TELPHONE_IS_EMPTY);
        } else if (!Utils.doRegularExpression(Constants.TELPHONE_REGRXP, telphone)) {
            throw new IllegalArgumentException(Constants.TELPHONE_FORMERR);
        }
    }

    /**
     * 检查注册用户名是否符合规则
     * 首字母不能为数字(防止占用手机号码)
     *
     * @throws IllegalArgumentException
     */
    public static void checkRegUsername(String username) {

        checkUsername(username);
        //首位不能为数字
        if (Utils.doRegularExpression("[0-9]{1}", username.substring(0, 1))) {
            throw new IllegalArgumentException(Constants.USERNAME_FORMERR);
        }
    }

    /**
     * 检查手机验证码是否符合规则
     *
     * @param vCode
     * @throws IllegalArgumentException
     */
    public static void checkVcode(String vCode) {

        if (TextUtils.isEmpty(vCode)) {
            throw new IllegalArgumentException(Constants.VCODE_IS_EMPTY);
        } else if (!Utils.doRegularExpression(Constants.VCODE_REGRXP, vCode)) {
            throw new IllegalArgumentException(Constants.VCODE_FORMERR);
        }
    }

}
